package com.wu.client.controller;

import com.wu.client.constant.PlaylistCategories;
import com.wu.client.service.PlaylistService;
import com.wu.client.vo.res.PageResp;
import com.wu.client.vo.res.playlist.PlaylistBaseResp;
import com.wu.client.vo.res.playlist.PlaylistCategoriesResp;
import com.wu.client.vo.res.playlist.PlaylistDetailResp;
import com.wu.client.vo.res.playlist.PlaylistResp;
import com.wu.common.convertion.result.Result;
import com.wu.common.convertion.result.Results;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Cousin
 * @date 2025/3/15
 * @Description
 */
@RestController
@RequestMapping("playlists")
@RequiredArgsConstructor
public class PlaylistController {
    private final PlaylistService playlistService;
    @GetMapping("/{id}")
    public Result<PlaylistDetailResp> get(@PathVariable("id") Long id) {
        PlaylistDetailResp playlistResp = new PlaylistDetailResp();
        playlistResp.setCreatedAt("2024-5-8");
        playlistResp.setId(1L);
        playlistResp.setTitle("我的歌单");
        playlistResp.setCover("/img/cover/4.jpg");
        playlistResp.setSongCount(10000);
        playlistResp.setDescription("我顶顶顶顶");
        playlistResp.setIsLiked(true);
        playlistResp.setFavoriteCount(1000);
        playlistResp.setPlayCount(1000);
        playlistResp.setCreatorUrl("/img/avatar/2.jpg");
        playlistResp.setCreator("Cousin");
        return Results.success(playlistResp);
    }

    //http://localhost:8888/api/playlists?page=1&limit=24&categoryId=1
    @GetMapping Result<PageResp<PlaylistBaseResp>> getPlaylists(@RequestParam Integer page, @RequestParam Integer limit
    , @RequestParam(required = false)  Integer category,@RequestParam(required = false) Long userId){
        return Results.success(playlistService.getPlaylists(page,limit,category,userId));
    }
    @GetMapping("query")
    public Result<PageResp<PlaylistBaseResp>> queryInPage(@RequestParam Integer page,@RequestParam Integer limit,@RequestParam String query){
        return Results.success(playlistService.getPlaylists(page,limit,null,null));
    }
}
